#loading data
load("house_elections.rda")
load("candidates.rda")
load("committees.rda")
load("contributions.rda")
library(tidyverse)
require(scales)
library(ggthemes)
#filtered candidates
candidates_filtered <- candidates %>%
select(-c(cand_st1, cand_st2, cand_city, cand_state,cand_zip))
#filtered contributions
contributions_filtered <- contributions %>%
select(cmte_id, name, city, state, zip_code, transaction_dt, transaction_amt, cand_id, other_id)
#filter committees
committees_filtered <- committees %>%
select(cmte_id, cmte_name, cmte_city, cmte_state, cmte_zip, cmte_party_affiliation, cand_id)
#joining the filtered tables
complete_table <- left_join(candidates_filtered, contributions_filtered, by = "cand_id")
#creating list of state names for function
c <- complete_table %>%
select(cand_office_state, cand_election_yr, cand_office_state) %>%
distinct(cand_office_state)
kimtest <- complete_table %>%
filter(cand_election_yr == "2012", cand_office == "S")
#Final list
state_names <- distinct(kimtest, cand_office_state) %>%
.$cand_office_state
#lubridate
require(lubridate)
#changes int dates into actual dates
dates <- complete_table %>%
mutate(date = mdy(transaction_dt))
# sorting the complete table, only interested in Senate, 2012 races in the timeline of the election year
filtered_names <- dates %>%
filter(cand_election_yr == "2012", cand_office == "S", date >= "2012-01-01")%>%
group_by(cand_name, transaction_dt) %>%
mutate(total = sum(transaction_amt))
## [[1]]
##
## [[2]]
##
## [[3]]
##
## [[4]]
##
## [[5]]
##
## [[6]]
##
## [[7]]
##
## [[8]]
##
## [[9]]
##
## [[10]]
##
## [[11]]
##
## [[12]]
##
## [[13]]
##
## [[14]]
##
## [[15]]
##
## [[16]]
##
## [[17]]
##
## [[18]]
##
## [[19]]
##
## [[20]]
##
## [[21]]
##
## [[22]]
##
## [[23]]
##
## [[24]]
##
## [[25]]
##
## [[26]]
##
## [[27]]
##
## [[28]]
##
## [[29]]
##
## [[30]]
##
## [[31]]
##
## [[32]]
##
## [[33]]
blog post We used data from the Federal Election Commission